package com.ruoyi.question.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.question.domain.DtRanking;
import com.ruoyi.question.service.IDtRankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 排行榜管理Controller
 *
 * @author llc
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/question/ranking")
public class DtRankingController extends BaseController {
    @Autowired
    private IDtRankingService dtRankingService;

    /**
     * 查询排行榜管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:ranking:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtRanking dtRanking) {
        startPage();
        List<DtRanking> list = dtRankingService.selectDtRankingList(dtRanking);
        return getDataTable(list);
    }

    /**
     * 导出排行榜管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:ranking:export')")
    @Log(title = "排行榜管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtRanking dtRanking) {
        List<DtRanking> list = dtRankingService.selectDtRankingList(dtRanking);
        ExcelUtil<DtRanking> util = new ExcelUtil<DtRanking>(DtRanking.class);
        util.exportExcel(response, list, "排行榜管理数据");
    }

    /**
     * 使用用户id获取排行榜管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:ranking:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(dtRankingService.selectDtRankingByUserId(userId));
    }

    /**
     * 新增排行榜管理
     */
    @PreAuthorize("@ss.hasPermi('question:ranking:add')")
    @Log(title = "排行榜管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtRanking dtRanking) {
        return toAjax(dtRankingService.insertDtRanking(dtRanking));
    }

    /**
     * 修改排行榜管理
     */
    @PreAuthorize("@ss.hasPermi('question:ranking:edit')")
    @Log(title = "排行榜管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtRanking dtRanking) {
        return toAjax(dtRankingService.updateDtRanking(dtRanking));
    }

    /**
     * 删除排行榜管理
     */
    @PreAuthorize("@ss.hasPermi('question:ranking:remove')")
    @Log(title = "排行榜管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dtRankingService.deleteDtRankingByIds(ids));
    }

}
